package com.enjoy.tree;

public class RedBlackTree {
    private final int R = 0;

    private final int B = 1;

    private final Node nil = new Node(-1);

    private Node root = nil;

    public class Node {
        int key = -1;
        int color = B;
        Node left;
        Node right;
        Node p;

        public Node(int key) {
            this.key = key;
        }

        @Override
        public String toString() {
            return "Node{" + "key=" + key + ", color=" + color + ", left=" + left.key + ", right=" + right.key + ", p=" + p.key + '}';
        }
    }

    public void printTree(Node node) {
        if (node == nil) {
            return;
        }
        printTree(node.left);
        System.out.println(node);
        printTree(node.right);
    }

    private void insert(Node node) {
        Node temp = root;
        if (root == nil) {
            root = node;
            node.color = B;
        } else {
            node.color = R;
            while (true) {
                if (node.key < temp.key) {
                    if (temp.left == nil) {
                        temp.left = node;
                        node.p = temp;
                        break;
                    } else {
                        temp = temp.left;
                    }
                } else {
                    if (temp.right == nil) {
                        temp.right = node;
                        node.p = temp;
                        break;
                    } else {
                        temp = temp.right;
                    }
                }
            }
            fixTree(node);
        }
    }

    private void fixTree(Node node) {

    }

}
